
pkgname=man-pages
pkgver=4.16
_posixver=2013-a
pkgrel=1
pkgdesc="Linux man pages"
arch=('x86_64')
license=('GPL')
url="https://www.kernel.org/doc/man-pages/"
groups=('base')
depends=()
source=("https://www.kernel.org/pub/linux/docs/man-pages/$pkgname-$pkgver.tar.xz"
        "https://www.kernel.org/pub/linux/docs/man-pages/man-pages-posix/$pkgname-posix-${_posixver}.tar.xz")
sha256sums=('47ffcc0d27d50e497e290b27e8d76dbed4550db14c881f25b771bcaf28354db4'
            '19633a5c75ff7deab35b1d2c3d5b7748e7bd4ef4ab598b647bb7e7f60b90a808')

build() {
  cd $pkgname-$pkgver
  
  # move the posix pages
  mkdir -p ${srcdir}/$pkgname-$pkgver/man0
  for sect in 0 1 3; do
    sed -i "/^\.so /s/man${sect}p/man$sect/" "${srcdir}/$pkgname-posix-${_posixver}/man${sect}p"/*
    mv -iv ${srcdir}/$pkgname-posix-${_posixver}/man${sect}p/* ${srcdir}/$pkgname-$pkgver/man$sect/
  done
}

package() {
  cd $pkgname-$pkgver

  make prefix=${pkgdir}/usr install
  
  install -m755 -d ${pkgdir}/usr/share/licenses/${pkgname}
  install -m644 ${srcdir}/$pkgname-posix-${_posixver}/POSIX-COPYRIGHT ${pkgdir}/usr/share/licenses/${pkgname}/POSIX-COPYRIGHT

  cd ${pkgdir}/usr/share/man
  # part of coreutils 
  rm -f man1/{chgrp,chmod,chown,cp,dir,dd}.1
  rm -f man1/{df,dircolors,du,install,ln,ls}.1
  rm -f man1/{mkdir,mkfifo,mknod,mv,rm,rmdir}.1
  rm -f man1/{touch,vdir}.1
  # part of shadow
  rm -f man5/passwd.5
  rm -f man3/getspnam.3
  # part of diffutils
  rm -f man1/diff.1
  # part of xf86-input-mouse
  rm -f man4/mouse.4
  # part of libbsd
  rm -f man3/explicit_bzero.3
}
